package com.summer.springboot.jpa.service;

import com.summer.springboot.jpa.entity.User;
import com.summer.springboot.jpa.repository.UserRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@AllArgsConstructor
@Service
public class UserServiceImpl implements UserService {

    private final UserRepository userRepository;

    @Override
    public User saveUser(User user) {
        return userRepository.saveAndFlush(user);
    }

    @Override
    public User getUserById(Long userId) {
        return userRepository.getById(userId);
    }

    @Override
    public List<User> getAll() {
        return userRepository.findAll();
    }

    @Override
    public void delByUserId(Long userId) {
        userRepository.deleteById(userId);
    }

    @Override
    public int updateByName(Long userId, String name) {
        return userRepository.updateByUsername(userId, name);
    }
}
